<?php
	require_once("conexao.php");
	$nome = $_POST["nome"];
	$endereco = $_POST["endereco"];
	$bairro = $_POST["bairro"];
	$numero = $_POST["numero"];
	$complemento = $_POST["complemento"];
	$email = $_POST["email"];
	$telefone = $_POST["telefone"];
	$celular = $_POST["celular"];
	$query = "select * from tb_cliente where ";

	if ($nome==null && $endereco==null && $bairro==null && $numero==null && $complemento==null && $email==null && $telefone==null && $celular==null){
		$rest = "SELECT * FROM tb_cliente ";
	}else{
		if($nome!=null){
			$query = $query."nome like '%".$nome."%' and ";
		}
		if($email!=null){
			$query = $query."email like '%".$email."%' and ";
		}
		if($endereco!=null){
			$query = $query."endereco like '%".$endereco."%' and ";
		}
		if($bairro!=null){
			$query = $query."bairro like '%".$bairro."%' and ";
		}
		if($numero!=null){
			$query = $query."numero like '%".$numero."%' and ";
		}
		if($complemento!=null){
			$query = $query."complemento like '%".$complemento."%' and ";
		}
		if($telefone!=null){
			$query = $query."telefone like '%".$telefone."%' and ";
		}
		if($celular!=null){
			$query = $query."celular like '%".$celular."%' and ";
		}
		$rest = substr("$query", 0, -4);
	}
	$resource_result = mysql_query($rest);

	echo '<table>';
	while($resultado = mysql_fetch_array($resource_result)){
		echo '<tr><td>Nome: </td>';
		echo '<td>'.utf8_encode($resultado['nome']).' '.$resultado['sobrenome'].'</td>';
		echo '<tr><td>E-mail:</td><td>'.$resultado['email'].'</td></tr>';
		echo '<tr><td>Telefone:</td><td>'.$resultado['telefone'].'</td></tr>';
		echo '<tr><td>Celular:</td><td>'.$resultado['celular'].'</td></tr>'; 
	}
	echo '</table>';
?>
